using LitJson;
using UnityEngine;

namespace abilities.triggers.conditions
{
    /**触发器的条件包含一个check方法，如果它返回真则认为已经完成。*/
    public class AbilityTriggerCondition
    {

        public virtual bool FromJson(JsonData value)
        {
            return false;
        }

        // 检查条件，如果真则认为条件已经完成。
        public virtual bool Check(AbilityContext context)
        {
            return false;
        }

        public static AbilityTriggerCondition CreateFromJson(JsonData value)
        {
            AbilityTriggerCondition result = null;
            string type =(string)value["type"];

            if ("Chance" == type)
            {
                result = new AbilityTriggerConditionChance();
            }
            else if ("TargetsAround" == type)
            {
                result = new AbilityTriggerConditionTargetsAround();
            }
            else if ("ParameterValue" == type)
            {
                result = new AbilityTriggerConditionParameterValue();
            }
            else
            {
                Debug.LogError("Unknown condition trigger type ：" + type);
            }

            if (result != null)
            {
                result.FromJson(value);
            }

            return result;
        }
    }
}